package org.gpp.proj1.demo.map;

import org.gpp.proj1.demo.map.sky.PreparedSkyBox;
import org.gpp.proj1.map.combat.CombatMap;
import org.gpp.proj1.map.parser.CombatMapFileParser;
import org.gpp.proj1.map.renderer.CombatMapNodeBuilder;

import com.jme.app.AbstractGame;
import com.jme.app.SimpleGame;
import com.jme.math.Vector3f;
import com.jme.scene.Node;

public class CombatMapDemo extends SimpleGame {
	
	private Node sky;

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		CombatMapDemo demo = new CombatMapDemo();
		demo.setDialogBehaviour(AbstractGame.FIRSTRUN_OR_NOCONFIGFILE_SHOW_PROPS_DIALOG);
		demo.start();
	}

	/**
	 * @see com.jme.app.BaseSimpleGame#simpleInitGame()
	 */
	@Override
	protected void simpleInitGame() {
		
		display.setTitle("Combat Map Test");
		this.cam.setLocation(new Vector3f(128,64,128));
		this.cam.lookAt(new Vector3f(50, 0, 50), new Vector3f(0, 1, 0));
		
		this.sky = new PreparedSkyBox("res/map/desert_skybox.sky").getSkyNode();

		CombatMap map = null;
		try {
			map = CombatMapFileParser.parseFile( "res/map/combatMap01.cmp");
		} catch (Exception e) {
			e.printStackTrace();
		}
		
		if( map != null ) {
			rootNode.attachChild( CombatMapNodeBuilder.buildNode( map, "Map 01" ) );
			this.rootNode.attachChild(this.sky);
		}
	}
	
	@Override
	protected void simpleUpdate() {
		this.sky.setLocalTranslation(this.cam.getLocation());
	}
}